<template>
  <transition name="fade">
    <div v-if="isVisible" class="confirm-dialog">
      <div class="confirm-content">
        <p>{{ message }}</p>
        <div class="confirm-actions">
          <button class="confirm-button" @click="isconfirm">{{ confirmText }}</button>
          <button class="cancel-button" @click="iscancel">{{ cancelText }}</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script setup>
import { ref, defineProps, onMounted, defineEmits } from 'vue';

const emits = defineEmits(['isconfirm', 'iscancel']);
const props = defineProps({
  isVisible: {
    type: Boolean,
    required: true
  },
  message: {
    type: String,
    required: true
  },
  confirmText: {
    type: String,
    default: () => { 'Confirm' }
  },
  cancelText: {
    type: String,
    default: () => { 'Cancel' }
  }
});

function isconfirm() {
  emits('isconfirm');
}

function iscancel() {
  emits('iscancel');
}

onMounted(() => {});
</script>

<style scoped>
.confirm-dialog {
  position: fixed;
  top: 100px; /* 靠近顶部100px */
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(255, 255, 255, 0.9); /* 白色半透明背景 */
  border-radius: 12px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  width: 350px;
  padding: 24px;
  text-align: center;
  /* 这里做特殊处理因为这个需要放到全局导航9999一层 */
  z-index: 9999;
  border: 1px solid rgba(0, 0, 0, 0.1); /* 添加边框增强层次感 */
}

.confirm-content p {
  font-size: 16px;
  color: #2c3e50; /* 深蓝色文字 */
  margin-bottom: 24px;
}

.confirm-actions {
  display: flex;
  justify-content: space-around;
}

.confirm-actions button {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.3s ease, transform 0.2s ease;
}

.confirm-actions button:hover {
  transform: translateY(-2px);
}

.confirm-button {
  background-color: #3498db; /* 浅蓝色 */
  color: white;
}

.confirm-button:hover {
  background-color: #2980b9; /* 深一点的蓝色 */
}

.cancel-button {
  background-color: #e74c3c; /* 红色 */
  color: white;
}

.cancel-button:hover {
  background-color: #c0392b; /* 深一点的红色 */
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>